package cn.xwt.weidisk.service.impl;

import cn.xwt.weidisk.constant.ServiceError;
import cn.xwt.weidisk.mapper.CategoryMapper;
import cn.xwt.weidisk.mapper.LinkMapper;
import cn.xwt.weidisk.pojo.dao.CategoryDo;
import cn.xwt.weidisk.pojo.dao.LinkDo;
import cn.xwt.weidisk.pojo.dto.CategoryData;
import cn.xwt.weidisk.service.CategoryService;
import cn.xwt.weidisk.util.CommonUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 薛慰涛
 */
@Service("categoryService")
public class CategoryServiceImpl implements CategoryService {

    @Resource
    CategoryMapper categoryMapper;


    @Override
    public ServiceError insertCategory(CategoryDo category) {
        if (existsCategory(category)) {
            return ServiceError.CATEGORY_EXISTS;
        }
        if (categoryMapper.insertCategory(category) == 1) {
            return ServiceError.SUCCESS;
        }
        return ServiceError.ERROR;
    }

    @Override
    public List<CategoryDo> selectCategoryList(Long uid) {
        return categoryMapper.selectCategoryList(uid);
    }

    @Override
    public boolean existsCategory(CategoryDo category) {
        Long id = categoryMapper.selectId(category);
        return id != null;
    }

    @Override
    public boolean isCurrentUser(Long id, Long uid) {
        CategoryDo category = new CategoryDo();
        category.setId(id);
        category.setUid(uid);
        return existsCategory(category);
    }

    @Override
    public void deleteCategory(Long id) {
        categoryMapper.deleteCategory(id);
    }

    @Override
    public void renameCategory(CategoryDo category) {
        categoryMapper.updateName(category);
    }
}
